home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 8873 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  3.0 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: C preprocessor problem
  5. Date: Wed, 06 Mar 96 20:26:21 GMT
  6. Organization: none
  7. Message-ID: <826143981snz@genesis.demon.co.uk>
  8. References: <313A3ABE.11CD@accent.net>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <313A3ABE.11CD@accent.net> eros-ssm@accent.net "Daniel Bolduc" writes:
  15.  
  16. >In the past, I programmed with the release  3.2.4 of SCO Operating and
  17. >Development System.   The C compiler was Microsoft C 6.0.
  18. >
  19. >With this compiler, i can use the maximum of the preprocessor without 
  20. >problem.
  21. >The preprocessor is recursive, he have to resolve expression until the 
  22. >code
  23. >is reduce to the simple code.  With  "cc" command i never had any error.
  24.  
  25. The C preprocessor is not recursive in any sense that I can fathom. Ceratinly
  26. macro replacements can be nested but a single macro can't be expanded
  27. recursively.
  28.  
  29. >But now, with the new compiler of SCO OpenServer, it didn't resolve the 
  30. >expression recursively.
  31. >It translate expression with the appropriate code, but if the code use a
  32. >variable, the reference is not resolve and i get a compiler error.
  33.  
  34. The new compiler correctly diagnosed a bug in your code which the old
  35. compiler failed to diagnose.
  36.  
  37. ...
  38.  
  39. >#define S_FVAL(idAlias,idFld) \
  40. >   zaoFld##idAlias[##idFld##idAlias].u.cpValue
  41.  
  42.                     ^^
  43.  
  44. Here you are trying to paste [ to the beginning of the identifier which
  45. creates an illegal pp-token. It should be a separate token so remove the
  46. ## indicated. 
  47.  
  48. >#define C_FVAL(idAlias,idFld) \
  49. >   zaoFld##idAlias[##idFld##idAlias].u.cValue
  50. >#define I_FVAL(idAlias,idFld) \
  51. >   zaoFld##idAlias[##idFld##idAlias].u.iValue
  52. >#define L_FVAL(idAlias,idFld) \
  53. >   zaoFld##idAlias[##idFld##idAlias].u.lValue
  54. >#define R_FVAL(idAlias,idFld) \
  55. >   zaoFld##idAlias[##idFld##idAlias].u.rValue
  56.  
  57. Similarly.
  58.  
  59. >//=========================================================================
  60.  
  61. // is a syntax error in C. If you want to write C code ise /* and */ to
  62. delimit comments. Compile your code forcing ANSI compliance from your
  63. compiler (possibly using -ansi or 'man cc' if not).
  64.  
  65. >If i compile the source like this, the program works:
  66. >
  67. >#cc -E -P test.c > test2.c
  68. >
  69. >"test.c", line 123: error: invalid token: [iNumTest
  70. >"test.c", line 123: error: Syntax error before or at: ]
  71. >"test.c", line 124: error: invalid token: [cNameTest
  72. >"test.c", line 125: error: invalid token: [cSexTest
  73. >"test.c", line 126: error: invalid token: [lActiveTest
  74. >"test.c", line 127: error: invalid token: [rSalaryTest
  75. >
  76. >#cc test2.c
  77.  
  78. In that case you are writing the preprocessor output to a file. What it can't
  79. write is the way you forced tokenisation with ##. The 2nd time it was compiled
  80. there were no ## to cause any problems.
  81.  
  82. -- 
  83. -----------------------------------------
  84. Lawrence Kirby | fred@genesis.demon.co.uk
  85. Wilts, England | 70734.126@compuserve.com
  86. -----------------------------------------
  87.